<?php

/**
 * general component.
 *
 * @package    Redsea20
 * @subpackage general
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class generalComponents extends sfComponents
{    
 
  public function executeRedseaHeader()
  {
    //$this->totalMails = 15;
    // Gets the count of UNREAD messages
    $result = Doctrine_Query::create()
                        ->select('COUNT(msg.id)')
                        ->from('message msg')
                        ->leftJoin('msg.Entity r')
                        ->where('r.id='.$this->getUser()->getAttribute('currentuser')->getId())
                        ->andwhere('msg.messagestatustyperefid='.Types::$MSG_STATUS['UNREAD']);
    // Gets the count of UNREAD message replies
    $replyResult = Doctrine_Query::create()
                        ->select('COUNT(msgrply.id)')
                        ->from('messagereply msgrply')
                        ->where('msgrply.toentityid='.$this->getUser()->getAttribute('currentuser')->getId())
                        ->andwhere('msgrply.replystatustyperefid='.Types::$MSG_STATUS['UNREAD']);
//      $result = Doctrine_Query::create()
//                        ->select('COUNT(msg.id)')
//                        ->from('message msg')
//                        ->leftJoin('msg.Entity r')
//                        ->where('r.id='.$this->getUser()->getAttribute('userid').' OR (msg.issharedmessage=1 AND msg.fromentityid='.$this->getUser()->getAttribute('userid').')')
//                        ->andwhere('msg.messagestatustyperefid='.Types::$MSG_STATUS['UNREAD']);

    $this->totalMails = $replyResult->fetchOne(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR) +  $result->fetchOne(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR);
  }

  public function executeMessageList()
  {   
    $this->messageList = MessagereplyTable::getInstance()->getLatestReplyMessages();
   
  }

  public function executeMessageDetail()
  {

  }

  public function executeSetAttributeReport()
  {
        
  }

  public function executeNewConnectionCounter()
  {
      $currentUser = $this->getUser()->getAttribute('currentuser');
      
      $result = Doctrine_Query::create()
                    ->select('COUNT(ec.id)')
                    ->from('entityconnection ec')
                    ->where('ec.entityid='.$this->getUser()->getAttribute('currentuser')->getId())
                    ->andwhere('ec.connectionstatustyperefid='.Types::$CONN_STATUS["PENDING"]);

    $this->totalNewConnection = $result->fetchOne(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR);
  }

  public function executeFriendList()
  {
      //$currentUser = Entity::GetEntity($this->userID);
    //echo $currentUser->Entityconnection->get('id=1')->id;
//echo Entity::getFriendList($this->userID, $this->connectionStatus);
      $this->friendList = Entity::getFriendList($this->userID, $this->connectionStatus);
  }

  public function executeUserProfilePicture()
  {
      /*
       * Container of this component is passing the userid parameter
       * so if parameter is null then error should be raiseed
       */
      $this->user = Entity::GetEntity($this->userid);
  }

  public function executeCommunityMemberList()
  {
      $this->profileUser = Entity::GetEntity($this->userId);

      $this->memberList = Entity::getRBISCommunity (Types::$COMMUNITY_MEMBER_TYPE[Types::$COMMUNITY_MEMBER_TYPE_ALL], $this->profileUser->getId());

  }
}
?>